package com.lbs.view.adapter;

import java.util.List;

import com.lbs.tdrive.data.AlertData;

import com.lbs.tdrive.R;
import com.lbs.tdrive.activity.Alerts;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AlertAdapter extends BaseAdapter {
private Context ctx;
	
	private  Handler handler;
	private List<AlertData> alertListData;
	
	
	public AlertAdapter(Context ctx,Handler handler, List<AlertData> alertListData) {
		this.ctx= ctx;
		this.handler=handler;
		this.alertListData=alertListData;
	}


	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return alertListData.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertview, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(ctx);
		View v = inflater.inflate(R.layout.alert_view, null);
		TextView tv =  (TextView) v.findViewById(R.id.textView1);
		ImageView iv=(ImageView)v.findViewById(R.id.imageView2);
		final int pos=position;
		iv.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Message msg=new Message();
				msg.what=Alerts.DELETE_ALERT;
				msg.arg1=pos;
				handler.sendMessage(msg);
				
			}
		});
	
		
		tv.setText(alertListData.get(position).getAlertName());
		return v;
	}

}

		
		
		
		
		
		
		